(function () {
	//获取商铺信息
	var iShopId = parseInt(page.url.get('id'));	 
	var oMenu = {};
		getShopInfo ();
	function getShopInfo ()
	{

		//导航
		getJson(Domain+'/comm/widget/doSearchShopWidgetData.do', {
			widgetName:'shop_pc_top_navigation',
			widgetDataType:2,
			shopId:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{
				renderTmp('#navlist', 'navlisttpl',res);
		  }
		});

		//获取优惠券
		getJson(Domain+'/shop/doSearchShopCashCouponList.do', {
			id:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	renderTmp('#couponlist', 'couponlisttpl',res);

		  }
		});
	

		//商店基本信息
		getJson(Domain+'/shop/doLoadShopInfo.do', {
			id:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

		  	$('#banner').append('<img data-lazyload="'+res.data.shop.bannerUrl+'" alt="">');
		  	lazyLoad.refresh(true);
		  	res.data.widgetData = oMenu;
	  	 	renderTmp('#shopdetails', 'shopdetailstpl',res);
	  	 	
		  }
		});

	};


	 getPageData({
	 shopId:iShopId
	 });  //获取产品列表 

	 function getPageData (Filter)
	 {
	 	var Filter = Filter;
	 		Filter.page = page.page;
	 		Filter.pageSize = page.pageSize;
	 	getJson(Domain+'/ec/promo/doSearchShopPromoGoodsList.do', Filter, function (res) {
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{	


	  		  page.nowPage = res.data.goodsList.pageId;
      		  page.pageCount = res.data.goodsList.pageCount;
      		  
      		  if(!res.data.goodsList.rows.length){
		        $('.am-pagination').remove();
		        $('#itemlist').empty();
		        $('.list-body').append('<li class="empty_div">'+language.noGoods+'</li>');
		        return
		      }

		     $('#itemlist').empty();

			 renderTmp('#itemlist', 'itemlisttpl',res);
			 	lazyLoad.refresh(true);

			 	for (var i = 0 ; i < res.data.goodsList.rows.length; i++)
			 	{
			 		$(".countdown").eq(i).downCount({
					date: moment(res.data.goodsList.rows[i].promo.endTime).format('YYYY-MM-DD HH:mm:ss'),
					offset:+8,
					now_date:moment(new Date()).format('YYYY-MM-DD HH:mm:ss')},
						
						function () {alert("倒计时结束");

					});
			 	}

			 	

			 	$('.am-pagination').createPage({
			        current: page.page,
			        type: 1,
			        pageCount: page.pageCount,
			        center: 3,
			        showLen: 11,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });

			 	$('.textpage').createPage({
			        current: page.page,
			        type: 2,
			        pageCount: page.pageCount,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });
		  }
		})
	 }

})();